package com.elm.controller;

import com.elm.mapper.UserMapper;
import com.elm.po.Wallet;
import com.elm.po.Transaction;
import com.elm.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/wallet")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping
    public Wallet getWallet() {
        return walletService.getWallet();
    }

    @PostMapping("/recharge")
    public int recharge(@RequestParam Double amount) {
        return walletService.recharge(amount);
    }

    @PostMapping("/withdraw")
    public int withdraw(@RequestParam Double amount) {
        return walletService.withdraw(amount);
    }

    @PostMapping("/transfer")
    public int transfer(@RequestParam int  fromUserId, @RequestParam int  toUserId,
                            @RequestParam Double amount, @RequestParam String remark) {
        return walletService.transfer(fromUserId, toUserId, amount, remark);
    }

    @GetMapping("/transactions")
    public List<Transaction> getTransactions() {
        return walletService.getTransactions();
    }

    @PostMapping("/repay")
    public int repay(@RequestParam double amount) {
        return walletService.repay(amount);
    }
}
